package easymall.controller.admin;

import javax.servlet.http.HttpSession;

import easymall.clients.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import easymall.po.Admin;

/*
 *后台登陆管理
 *分发后台登陆界面、登录验证
 * */
@Controller
@RequestMapping("/admincheck")
public class AdminLoginController {
	@Autowired
	private AdminService adminService;
	
	@RequestMapping("/login")
	public String login() {
		return "admin/login"; //跳转jsp
	}
	
	//验证登录
	@RequestMapping("/toLogin")
	public String toLogin(Admin admin,HttpSession session, Model model) {
		Admin madmin = adminService.login(admin);
		if(madmin != null) {
			session.setAttribute("admin", madmin);
			return "redirect:/admin/manage";
		}else {
			model.addAttribute("msg", "用户名或密码错误！");
//			return "admin/login";
			return "admin/login";
		}
	}
	
	//退出登录
	@RequestMapping("logout")
	public String logout(HttpSession session) {
		session.removeAttribute("admin");
		return "admin/login";
	}
	
}
